<style>
</style>
<script type="text/javascript">
$.extend({
  refresh_task_list: function() {
    if ($('#tabs_load').hasClass("oplog_load")) {
      $('#tb_oplog_mng').trigger("reloadGrid");
    }
  }
});

if (window.interval_task_list) {} else {
  window.interval_task_list = window.setInterval("$.refresh_task_list()", 100000);
}
$(document).ready(function() {
  var initial_width;

  var is_administrator = false
  if ('{{permission}}' == 'true') {
    is_administrator = true;
  }

  $('#tb_oplog_mng').jqGrid({
    url: '/grid_oplog',
    datatype: 'json',
    mtype: 'GET',
    colNames: ["编号", "操作日期", "操作", "模块", "对象", "操作结果", "详情", "操作者"],
    colModel: [{
      name: 'id',
      index: 'id',
      width: 10,
      align: 'left',
      hidden: true
    }, {
      name: 'created_at',
      index: 'created_at',
      width: 10,
      align: 'left',
      formatter: function(cellvalue, option) {
        return makeEllipsis(cellvalue, option);
      },
      unformat: function(cellvalue) {
        return cellvalue;
      }
    }, {
      name: 'operation',
      index: 'operation',
      width: 10,
      align: 'left',
      formatter: function(cellvalue, option) {
        return makeEllipsis(cellvalue, option, 'span');
      },
      unformat: function(cellvalue) {
        return cellvalue;
      }
    }, {
      name: 'resource',
      index: 'resource',
      width: 5,
      align: 'left',
      formatter: function(cell, option, row) {
        return makeEllipsis(cell, option, 'span');
      },
      unformat: function(cell) {
        return cell;
      }
    }, {
      name: 'oplog_obj',
      index: 'oplog_obj',
      width: 8,
      align: 'left',
      formatter: function(cell, option, row) {
        return makeEllipsis(cell, option, 'span');
      },
      unformat: function(cell) {
        return cell;
      }
    }, {
      name: 'status',
      index: 'status',
      width: 8,
      align: 'left',
      formatter: function(cellvalue, option, row) {
        return SelfTranslate(cellvalue)
      },
      unformat: function(cellvalue) {
        return cellvalue;
      }
    }, {
      name: 'detail',
      index: 'detail',
      width: 30,
      align: 'left',
      formatter: function(cellvalue, option) {
        return makeEllipsis(cellvalue, option, 'span');
      },
      unformat: function(cellvalue) {
        return cellvalue;
      }
    }, {
      name: 'username',
      index: 'username',
      width: 10,
      align: 'left',
      formatter: function(cellvalue, option) {
        return makeEllipsis(cellvalue, option, 'span');
      },
      unformat: function(cellvalue) {
        return cellvalue;
      }
    }],
    page: 1,
    rowNum: 10,
    sortname: 'id',
    sortorder: 'desc',
    viewrecords: true,
    multiboxonly: true,
    multiselectWidth: '60px',
    width: 1200,
    height: mainpanelHeight,
    autowidth: true,
    beforeSelectRow: function(rowid, e) {
      if ($(e.target).is('input')) {
        return true;
      }
      return false;
    },
    gridComplete: function() {
      var gridData = $(this).jqGrid('getRowData');
      jqgrid_page($(this), gridData);
      jqgrid_resize($(this));

      var ids = $(this).jqGrid('getDataIDs');
      var oplog_list_ids = $(this).attr("id");
      var level_high;
      for (var i = 0; i < ids.length; i++) {
        var detail = $(this).getCell(ids[i], "detail");
        var stat = $(this).getCell(ids[i], "status");
        var oplog_list_id = $(this).getCell(ids[i], "id");
        var oplog_list_created_at = $(this).getCell(ids[i], "created_at");
        if (detail == '') {
          $(this).jqGrid('setRowData', ids[i], {
            'detail': '--'
          });
        }
        var stat_show = '<span class="label label-success">' + stat + '</span>'
        if (stat == '失败') {
          stat_show = '<span class="label label-danger">' + stat + '</span>'
        }
      }
    },
    resizeStart: function() {
      initial_width = $(this).width();
    },
    resizeStop: function() {
      $(this).width(initial_width);
      $(".ui-jqgrid-hbox").find('.ui-jqgrid-htable').width(initial_width);
    },
  });

  var op_status_source = [
    ["成功", "成功"],
    ["失败", "失败"],
    ['全部', '全部']
  ];
  $('#oplog_status_select').rqDropDown({
    "datatype": "local",
    "source": op_status_source,
    "onchange": "op_status_select"
  });

  var op_source = [
    ["operation", "操作"],
    ["oplog_obj", "对象"],
    ["username", "操作者"],
    ["detail", "详情"],
    ["resource", "模块"]
  ];
  $('#op_search_select').rqDropDown({
    "datatype": "local",
    "source": op_source,
    "onchange": "select_search_field"
  });


  $("#search_button").on("click", function() {
    var search_key = $(this).siblings("#op_search_select").attr('realvalue');
    var search_val = $(this).siblings("#search_input").val();
    if (search_val) {
      $("#tb_oplog_mng").jqGrid('setGridParam', {
        page: 1,
        url: '/grid_oplog?search_key=' + search_key + "&search_val=" + search_val
      }).trigger('reloadGrid');
    } else {
      $("#tb_oplog_mng").jqGrid('setGridParam', {
        page: 1,
        url: "/grid_oplog"
      }).trigger('reloadGrid');
    }
  });


  $('#oplog_export').click(function() {
    angular.element("#OplogCtrl").scope().open("/oplog_export");
  });

});

function select_search_field(val, realvalue) {
  var placeholder = "请输入" + val + "名称";
  $("#search_input").attr('placeholder', placeholder)
}

function op_status_select(val, realvalue) {
  if (!realvalue) {
    return false
  }
  if (realvalue == '全部') {
    $("#tb_oplog_mng").jqGrid('setGridParam', {
      page: 1,
      url: "/grid_oplog"
    }).trigger('reloadGrid');
  } else {
    $("#tb_oplog_mng").jqGrid('setGridParam', {
      page: 1,
      url: "/grid_oplog?search_key=status&search_val=" + realvalue
    }).trigger('reloadGrid');
  }
}

function oplog_delte(ids) {
  $.post("/oplog_delete", {
    'ids': ids
  }, function(data) {
    if (data.reply.is_success) {
      $('#tb_oplog_mng').trigger("reloadGrid");
    } else {
      error = data.reply.error;
      SelfAlert(error);
    }
  });
}

function oplog_delete_confirm() {
  var rowIds = $("#tb_oplog_mng").jqGrid('getGridParam', 'selarrrow');
  if (rowIds == '') {
    SelfAlert('请先选择一条日志');
    return false;
  }
  var ids = ''
  for (var id = 0; id < rowIds.length; id++) {
    ids += rowIds[id] + ','
  }
  msg = '确认删除日志?';
  SelfConfirm(msg, oplog_delte, ids, "删除提示");
}
</script>
<div class="panel panel-f-style">
  <div class="panel-body">
    <div class="title-tag">
      <h3>操作日志</h3>
      <p>操作日志管理</p>
    </div>
    <div class="grid-tools">
      <!-- <div class="grid-search-down-arrow">
                <i class="fa fa-angle-down"></i>
            </div> -->
      <div class="grid-operate pull-left">
        <input class="rounded_dropdown" id="oplog_status_select" readonly="readonly" style="width: 100px;border-radius: 3px;" value="操作结果" realvalue="">
        <input class="rounded_dropdown" id="op_search_select" readonly="readonly" style="width: 100px;border-radius: 3px;" value="操作" realvalue="operation">
        <input type="input" id="search_input" class="page_input" style="width: 100px;border-radius: 3px;" placeholder="输入操作名称">
        <button type="button" class="btn btn-blue" id="search_button">搜索</button>
        <!--<button class="btn btn-blue" type="button"><i class="glyphicon glyphicon-trash"></i>移除</button>-->
      </div>
    </div>
    <div class="grid-body" id="div_oplog_tb">
      <table id="tb_oplog_mng"></table>
    </div>
  </div>
</div>
<!-- <div class="panel panel-default" ng-controller="OplogCtrl" id="OplogCtrl">
    <div class="panel-body">
        <div class="item_toolsbar">
            <input class="rounded_dropdown" id="oplog_status_select" readonly="readonly" value="操作结果" realvalue="">
        </div>
        <div id="div_oplog_tb">
                <table id="tb_oplog_mng"></table>
                <hr/>
                <div id="div_oplog_mng_pager"></div>
        </div>
        <button class="page_button oplog_export" id="oplog_export" style="display:none">导出</button>
        {% if permission == 'true' %}
        <button class="page_button oplog_del" id="oplog_delte" onclick=oplog_delete_confirm() >删除</button>
        {% endif %}
    </div> panel-body
    </div>
</div> -->
